(function(){
    $(".back").click(function(){
        $("body,html").animate({scrollTop:0},500)
    })
    var str=window.location.href;
    var brandTitleId=str.split("=")[1].split("&")[0]
    var text=str.split("&")[1].split("=")[1]
    text=decodeURI(text)
    console.log(brandTitleId)
    console.log(text)

    var productId=[],productName=[],brandName=[]
    
    $(".text").html(text)

    $.ajax({
        type:"GET",
        url:"http://chst.vip:1234/api/getbrandproductlist",
        data:{brandtitleid:brandTitleId}
    }).then(res=>{
        console.log(res)
        let html=""
        res.result.forEach(function (item,index) { 
            html+=`
            <li>
                ${item.productImg}
                <div>
                <p>${item.productName}</p>
                <p>${item.productPrice}</p>
                <p>${item.productQuote} <span>${item.productCom}</span> </p>
                </div>
            </li>
            `
            productId[index]=item.productId
            productName[index]=item.productName.split(" ")[0]
            brandName[index]=item.brandName
         })
         $(".box").html(html)
         console.log(productName)

         for(let i=0;i<productId.length;i++){
             $(".box").children("li:eq("+i+")").click(function(){
                 window.location.href="http://127.0.0.1:5500/%E9%A1%B9%E7%9B%AE/pages/shoppingDetail.html?productid="+productId[i]+"&category="+brandName[i]+"&productName="+productName[i]
             })
         }
    })
})() 